/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * 
 * 先序遍历
 * @param {TreeNode} root
 * @return {number[]}
 */
 var preorderTraversal = function(root) {
    let res = []
     tools(root)
    return res

    function tools(root){
        if(!root) return ;
        res.push(root.val)
        tools(root.left)
        tools(root.right)
    }
};

/**
 * 后序遍历
 * @param {TreeNode} root
 * @return {number[]}
 */
 var postorderTraversal = function(root) {
     let res = []
    tools(root)
    return res;
    function tools(root){
        if(!root) return;
        tools(root.left)
        tools(root.right)
        res.push(root.val)
    }
};


/**
 * 中序遍历
 * @param {TreeNode} root
 * @return {number[]}
 */
 var inorderTraversal = function(root) {
    let res = []
   tools(root)
   return res;
   function tools(root){
       if(!root) return;
       tools(root.left)
       res.push(root.val)
       tools(root.right)
      
   }
};